<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    let a = [
        { id: 1, name: 'a', pid: 0 },
        { id: 2, name: 'aa', pid: 0 },
        { id: 3, name: 'aaa', pid: 1 },
        { id: 4, name: 'aaaa', pid: 2 },
        { id: 5, name: 'aaaaa', pid: 2 },
        { id: 6, name: 'aaaaaa', pid: 2 },
        { id: 7, name: 'aaaaaaa', pid: 1 },
        { id: 8, name: 'aaaaaaaa', pid: 3 },
        { id: 9, name: 'aaaaaaaaa', pid: 3 },
    ]
    let b = a.reduce(function (p, item, index, arr) {
        item.child = arr.filter(m => m.pid == item.id)
        if (item.pid == 0) {
            p.push(item)
        }
        return p
    }, [])
    console.log(b)

// *********************************************************************

    let user = [
        { id: 1, name: "李四", age: 20 },
        { id: 2, name: "张三", age: 30 },
        { id: 1, name: "李四", age: 20 }
    ]

    let c = [...new Set(user.map(item => JSON.stringify(item)))]

    let newArr = c.map(item => JSON.parse(item))
    console.log(newArr);


// *********************************************************************


    let arr1 = [12, 45, 23, 12, 56, 45, 99, 100]

    let u1 = new Set(arr1)
    console.log(u1);


    let arr2 = [12, 45, 23, 12, 56, 45, 99, 100]
    for (var i = 0; i < arr2.length; i++) {
        if (arr2.indexOf(arr2[i]) !== i) {
            arr2.splice(i, 1)
            i--;
        }
    }
    console.log(arr2);


    let arr3 = [12, 45, 23, 12, 56, 45, 99, 100]
    var aa = arr3.filter(function (item, index) {
        return arr3.indexOf(item) === index;
    })
    console.log(aa);



    let arr4 = [12, 45, 23, 12, 56, 45, 99, 100]
    console.log(Array.from(new Set(arr4)));
</script>